<template>
	<div>
		<MPageContainer ref="mPageContainer"></MPageContainer>
		<van-tabbar v-model="active">
			<van-tabbar-item name="home" icon="home-o" @click="onTabbarChangeHandler('home')">首页</van-tabbar-item>
			<van-tabbar-item name="work" icon="search" @click="onTabbarChangeHandler('work')">工作</van-tabbar-item>
			<van-tabbar-item name="workflow" icon="setting-o" @click="onTabbarChangeHandler('workflow')">审批</van-tabbar-item>
			<van-tabbar-item name="my" icon="friends-o" @click="onTabbarChangeHandler('my')">我的</van-tabbar-item>
		</van-tabbar>
	</div>
</template>

<script>
	import MPageContainer from './MPageContainer.vue';
	import restUtil from '@/utils/restUtil.js';
	import constants from '@/utils/constants.js';
	import {
		Dialog
	} from 'vant';
	export default {
		name: "MMain",
		components:{MPageContainer},
		provide() {
			return {
				children: []
			}
		},
		data() {
			return {
				active: "home",
				mobileDashboardPage:""
			}
		},mounted() {
			window.document.title=constants.TITLE;
			this.axios.defaults.headers.common['X-Token'] = window.localStorage.getItem("token");
			this.$store.state.mobileMain=this;
			this.init();
		},
		methods: {
			init(){
				var that=this;
				restUtil.getAction(this,"mmain/init").then(
					function(response) {
						if (response.data.code == 1) {
							that.mobileDashboardPage = response.data.mobileDashboardPage;
							if(that.mobileDashboardPage!=null&&that.mobileDashboardPage!=""){
								that.loadServerPage(that.mobileDashboardPage);
							}
						} else {
							Dialog.alert({
								title: '提示',
								message: response.data.message,
							}).then(() => {
								// on close
							});
						}
					});
			},
			loadServerPage(pageCode) {
				this.$refs.mPageContainer.setComponent("mobile-page-component",{"pageCode":pageCode});
			},loadClientPage(pageCode) {
				this.$refs.mPageContainer.setComponent(pageCode,{});
			},onTabbarChangeHandler(index){
				this.active=index;
				if(index=="work"){
					this.loadClientPage("mmenu-page");
				}else if(index=="workflow"){
					//this.loadClientPage("wkftask-page");
					this.loadClientPage("m-workflow-task-management");
				}else if(index=="home"){
					this.loadServerPage(this.mobileDashboardPage);
				}else if(index=="my"){
					this.loadClientPage("mmy-page");
				}
			}
		},
	}
</script>

<style>
</style>
